package com.example.demo.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.demo.config.Result;
import com.example.demo.entity.Product;
import com.example.demo.mapper.ProductMapper;
import com.example.demo.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: lu
 * @Date: 2024-08-14-9:15
 * @Description:
 */
@RestController
@RequestMapping("/product")
public class ProductController {
    @Autowired
    ProductService productService;

    @Autowired
    ProductMapper productMapper;


    @GetMapping("/value")
    public Result<Object> getValue(){
        Product product = productMapper.selectById(2);
        //product.getProductName();
        //JSONObject attributes = product.getAttributes();
        //Object color = attributes.get("color");
        //System.out.println(color);
        Product product1 = new Product();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("color","blue");
        product1.setValue(String.valueOf(jsonObject));
        productMapper.insert(product1);

        String value = product.getValue();
        JSONObject object = JSONObject.parseObject(value);
        Object color = object.get("color");

        return Result.success(color);
    }
}
